/*
 * Created on Nov 17, 2003
 *
 */
package com.unash.asn;

import junit.framework.TestCase;

/**
 * @author Ashwini Gokhale
*/

public class Asn1DataTypeTest extends TestCase {

	/**
	 * Constructor for ASNIntegerTest.
	 * @param arg0
	 */
	public Asn1DataTypeTest(String arg0) {
		super(arg0);
	}//Asn1DataTypeTest(String arg0)

	public static void main(String[] args) {
		junit.swingui.TestRunner.run(Asn1DataTypeTest.class);
	}//main

	/*
	 * @see TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}//setUp

	/*
	 * @see TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}//tearDown

	final public void testAsnInteger() {
		AsnInteger i1 = new AsnInteger(1);
		AsnInteger i2 = new AsnInteger(1);
		AsnInteger i3 = new AsnInteger(2);
		assertEquals(1, i1.getInt());
		assertEquals(Integer.toString(1), i1.toString());
		assertEquals(i1, i2);
		assertEquals(i1.hashCode(), i2.hashCode());
		assertEquals((i1.hashCode()!= i3.hashCode()),true);
		assertEquals(i1.equals(i2),true);
		assertEquals(i2.equals(i3),false);
	}//testAsnInteger
	
	final public void testAsnString() {
		String str = "visible string s1";
		AsnVisibleString s1 = new AsnVisibleString(str);
		AsnVisibleString s2 = new AsnVisibleString(str);
		AsnVisibleString s3 = new AsnVisibleString("visible string s3");
		assertEquals(s1, s2);
		assertEquals((s1.hashCode() != s3.hashCode()),true);
		assertEquals(s1.equals(s3),false);
		assertEquals(s1.equals(s2),true);
		assertEquals(s1.hashCode(), s2.hashCode());
		assertEquals(s1.toString(), s2.toString());
		assertSame(str, s1.toString());
	}//testAsnString
	
	final public void testAsnBitString() {
		byte[] b1 = new byte[] {2};
		byte[] b2 = new byte[] {2};
		byte[] b3 = new byte[] {21};
		byte[] b4 = new byte[]{(byte)0xF0,(byte)0xF0};
			
		AsnBitString bs1 = new AsnBitString(b1,3);
		AsnBitString bs2 = new AsnBitString(b2,3);
		AsnBitString bs3 = new AsnBitString(b3,5);
		AsnBitString bs = new AsnBitString(b4,16);
		
		assertEquals(bs.toString(),"1111000011110000");
		
		assertEquals(bs1,bs2);
		
		assertEquals(bs1.equals(bs2),true);
		assertEquals(bs1.equals(bs3),false);
		
		assertEquals(bs1.hashCode(),bs2.hashCode());
		assertEquals((bs1.hashCode() != bs3.hashCode()),true);
		
		assertEquals(bs3.isBitSet(1),false);
		assertEquals(bs3.isBitSet(2),false);
		assertEquals(bs3.isBitSet(3),false);
		assertEquals(bs3.isBitSet(4),true);
		assertEquals(bs3.isBitSet(5),false);
		assertEquals(bs3.toString(),"00010");
		assertEquals(bs1.toString(),"000");
		
		AsnBitString bs5 = new AsnBitString(new byte[]{27,20},15);
		AsnBitString bs4 = new AsnBitString(new byte[]{27,125},15);
		
		assertEquals((bs5.hashCode() != bs4.hashCode()),true);
		assertEquals(bs5.equals(bs4),false);
				
		assertEquals(bs4.isBitSet(1),false);
		assertEquals(bs4.isBitSet(2),false);
		assertEquals(bs4.isBitSet(3),false);
		assertEquals(bs4.isBitSet(4),true);
		assertEquals(bs4.isBitSet(5),true);
		assertEquals(bs4.isBitSet(6),false);
		assertEquals(bs4.isBitSet(7),true);
		assertEquals(bs4.isBitSet(8),true);
		assertEquals(bs4.isBitSet(9),false);
		assertEquals(bs4.isBitSet(10),true);
		assertEquals(bs4.isBitSet(11),true);
		assertEquals(bs4.isBitSet(12),true);
		assertEquals(bs4.isBitSet(13),true);
		assertEquals(bs4.isBitSet(14),true);
		assertEquals(bs4.isBitSet(15),false);
		
		assertEquals(bs4.toString(),"000110110111110");
		assertEquals(bs5.toString(),"000110110001010");
							
	}//testAsnBitString
	
	
	final public void testAsnBoolean(){
		AsnBoolean b1 = new AsnBoolean(true);
		AsnBoolean b2 = new AsnBoolean(true);
		AsnBoolean b3 = new AsnBoolean(false);
		
		assertEquals(b1,b2);
		
		assertEquals(b1.equals(b2),true);
		assertEquals(b1.equals(b3),false);
		
		assertEquals(b1.hashCode(),b2.hashCode());
		assertEquals((b1.hashCode() != b3.hashCode()),true);
		//assertEquals(b1.toString(),Boolean.toString(b1.value));
	}//testAsnBoolean
	
	
	final public void testAsnOctetString(){
		byte[] b1 = new byte[] {2};
		byte[] b2 = new byte[] {2};
		byte[] b3 = new byte[] {3};
		byte[] b4 = new byte[] {1,10};
		
		AsnOctetString bs1 = new AsnOctetString(b1);
		AsnOctetString bs2 = new AsnOctetString(b2);
		AsnOctetString bs3 = new AsnOctetString(b3);
		
		assertEquals(bs1,bs2);
		assertEquals(bs1.equals(bs2),true);
		assertEquals(bs1.equals(bs3),false);
		
		assertEquals(bs1.hashCode(),bs2.hashCode());
		assertEquals((bs1.hashCode() != bs3.hashCode()),true);
		
		AsnOctetString myOctetString = new AsnOctetString(b4);
		assertEquals(myOctetString.isBitSet(1),false);
		assertEquals(myOctetString.isBitSet(2),false);
		assertEquals(myOctetString.isBitSet(3),false);
		assertEquals(myOctetString.isBitSet(4),false);
		assertEquals(myOctetString.isBitSet(5),false);
		assertEquals(myOctetString.isBitSet(6),false);
		assertEquals(myOctetString.isBitSet(7),false);
		assertEquals(myOctetString.isBitSet(8),true);
		
		assertEquals(myOctetString.isBitSet(9),false);
		assertEquals(myOctetString.isBitSet(10),false);
		assertEquals(myOctetString.isBitSet(11),false);
		assertEquals(myOctetString.isBitSet(12),false);
		assertEquals(myOctetString.isBitSet(13),true);
		assertEquals(myOctetString.isBitSet(14),false);
		assertEquals(myOctetString.isBitSet(15),true);
		assertEquals(myOctetString.isBitSet(16),false);
		
		AsnOctetString bs5 = new AsnOctetString(new byte[]{125});
		assertEquals(bs5.toString(),"01111101");
		 
	}//testAsnOctetString
	
}//AsnDataTypeTest
